﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package GameMode {
    import flash.events.*;
    import Engine.Managers.*;
    import Engine.Helpers.*;
    import Classes.*;
    import Transactions.*;
    import Classes.util.*;
    import Engine.*;

    public class GMLinkedObjectMove extends GMLinkedObjectEdit {

        public function GMLinkedObjectMove(_arg1:MapResource, _arg2:Boolean=false){
            super(_arg1, _arg2);
        }
        override protected function initializeGameModes():void{
            var _local1:GMObjectMove;
            var _local2:MapResource;
            this.preMoveLinkedObjects();
            _local1 = new GMObjectMove(m_parentObject, null, null, Constants.INDEX_NONE, false, m_parentObject.getPosition());
            _local1.setLinkedObjectMode(true);
            m_gmObjectEditModes.push(_local1);
            for each (_local2 in m_linkedObjects) {
                _local1 = new GMObjectMove(_local2, null, null, Constants.INDEX_NONE, false, _local2.getPosition());
                _local1.setLinkedObjectMode(true);
                m_gmObjectEditModes.push(_local1);
            };
        }
        protected function preMoveLinkedObjects():void{
            var _local1:Array;
            var _local2:Vector3;
            var _local3:Vector3;
            var _local4:MapResource;
            var _local5:MapResource;
            switch (m_parentObject.getItemName()){
                case "dock_house":
                    _local1 = new Array();
                    _local1 = Global.world.getObjectsByClass(Dock);
                    _local2 = m_parentObject.getPosition();
                    for each (_local5 in _local1) {
                        _local2.x = (_local2.x - 2);
                        _local3 = _local5.getPosition();
                        _local5.setPosition(_local2.x, _local2.y, _local2.z);
                        _local5.conditionallyReattach(true);
                        _local5.onObjectDrop(_local3);
                    };
                    _local2 = m_parentObject.getPosition();
                    _local4 = Global.world.getObjectsByClass(HarvestableShip)[0];
                    _local4.setPosition((_local2.x - 4), (_local2.y + 2), _local2.z);
                    _local3 = _local4.getPosition();
                    _local4.conditionallyReattach(true);
                    _local4.onObjectDrop(_local3);
                    break;
            };
        }
        override public function onMouseUp(_arg1:MouseEvent):Boolean{
            var _local3:GMObjectMove;
            var _local2:Boolean;
            for each (_local3 in m_gmObjectEditModes) {
                _local2 = _local3.isPositionValid();
                if (!_local2){
                    break;
                };
            };
            if (_local2){
                for each (_local3 in m_gmObjectEditModes) {
                    _local3.onMouseUp(_arg1);
                };
                Global.world.popGameMode();
                Sounds.play("place_building");
                TransactionManager.addTransaction(new TLinkedObjectMove(m_parentObject, m_linkedObjects));
            };
            super.onMouseUp(_arg1);
            return (true);
        }

    }
}//package GameMode 
